﻿using Microsoft.AspNetCore.Mvc;
using SqlSugarRedisDemo.Models;
using SqlSugarRedisDemo.Services;

namespace SqlSugarRedisDemo.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        readonly UserService userService;
        public UserController(UserService userService) 
        {
            this.userService = userService;
        }

        [HttpGet]
        public List<UserInfo> GetUserInfos([FromQuery]string? userName = "")
        {
            return userService.GetUserInfos(userName);
        }

        [HttpGet]
        public UserInfo GetUserById(long id)
        {
            return userService.GetUserById(id);
        }

        [HttpPost]
        public bool AddUser([FromBody]UserInfo userInfo)
        {
            return userService.AddUser(userInfo);
        }

        [HttpPost]
        public bool UpdUser([FromBody]UserInfo userInfo)
        {
            return userService.UpdUser(userInfo);
        }

        [HttpPost]
        public bool DelUser(long id)
        {
            return userService.DelUser(id);
        }

    }
}
